#ifndef VIDEOENCODER_H
#define VIDEOENCODER_H

extern "C"
{
#include <avcodec.h>
#include <avformat.h>
#include <swscale.h> 
#include <fifo.h>
}

#include <vector>

class VideoEncoder
{
	public:
		VideoEncoder();
		void EnableStreams(bool p_VideoEnabled, bool p_AudioEnabled);
		void SetupEncoder(char *filename, CodecID videoCodec, CodecID audioCodec);
		void FillParameters(int bitrate, int den, int num, int gopsize, int width, int height, int sample_rate, int audio_bitrate, int channels);
		void EncodeVideo(AVFrame *frame);
		void EncodeAudio( int16_t* samples, int buffersize);
		void OpenOutput();
		void CloseOutput();
		void SearchCodec();
		void SetTotalPTS(int pts);
		void SetConvertParameters(AVCodecContext* codec_context);
		bool IsAudioEnabled() { return AudioEnabled; };
		bool IsVideoEnabled() { return VideoEnabled; };

	private:

		bool VideoEnabled;
		bool AudioEnabled;
		char *name;
		AVOutputFormat *fmt;
		AVFormatContext *out_format_context;
		AVStream *video_stream;
		AVStream *audio_stream;
		AVCodecContext *video_codec_context;
		AVCodecContext *audio_codec_context;
		AVCodec *video_codec;
		AVCodec *audio_codec;
		int video_outbuf_size;
		uint8_t *video_outbuf;
		int audio_outbuf_size;
		uint8_t *audio_outbuf;
		int videopts;
		int audiopts;
		struct SwsContext *	gEncVideoConvertCtx;
		AVFrame *gEncVideoConvertFrame;
		int INPUT_HEIGHT;
		int INPUT_WIDTH;
		AVFifoBuffer gEncAudioFifo;				// FIFO to write incoming audio samples into
		uint8_t* gEncAudioFifoOutBuf;		// buffer to read _out_ of the FIFO into


};

#endif